from rest_framework.serializers import ModelSerializer
from .models import SKU

from drf_haystack.serializers import HaystackSerializer
from .search_indexes import SKUIndexs


class SKUModelSerializer(ModelSerializer):

    class Meta:
        model = SKU
        fields = ('id','name','default_image_url','price','comments')

class SKUIndexHaystackSerializer(HaystackSerializer):
    """
    返回搜索商品的序列化器
    """
    #  read_only=True 序列化返回
    object = SKUModelSerializer(read_only=True)
    class Meta:
        index_classes = [SKUIndexs]
        # 指定序列化后的数据
        fields = ('text','object')